<?php
namespace app\admin\controller;
use \think\Controller;
use \app\admin\model\User;
use \think\Cookie;
use think\Session;
class Users extends Controller
{
    public function _initialize(){
        if(!isLogin()){
            $this->redirect('/trade/login');
        }
    }
    public function index()
    {
        return $this->fetch();
    }

    //添加用户
    public function add(){
        $User=new User;
        $User->getUser();
        $this->assign('UserList',$User->getUser());
        return $this->fetch();
    }

    //用户列表
    public function entry(){
        return $this->fetch('list');
    }
    //编辑页面
    public function edit(){
        if(!Cookie::get('update_userid')){
            $this->error('页面错误，请稍候再试!');
        }
        Session::set('session_update_userid',Cookie::get('update_userid'));
        return $this->fetch();
    }

    //分配客户
    public function allot(){
        $User=new User;
        $this->assign('UserList',$User->getUser());
        return $this->fetch('allot');
    }

    //客户列表
    public function custom(){

        $User=new User;
        $res=$User->getCustom();
        $this->assign('UserList',$res);
        return $this->fetch('custom');
    }

    //客户编辑与更新
    public function allot_edit(){
        $id=Cookie::get('update_custom_id');
        if($id){
            $User=new User;
            $this->assign('UserList',$User->getUser());
            $this->assign('Custom',$User->getCustom($id));
            return $this->fetch('allot_edit');
        }
        return $this->error('你访问了一个错误的页面','/trade/user/custom');
    }

}
